#include <iostream>
#include <string>
using namespace std;
class Solution
{
public:
	bool isPalindrome(string s)
	{
		int i = 0;
		int j = s.size() - 1;
		auto check = [&](int c)-> bool
			{
				if (isdigit(c))
					return true;
				if (isalpha(c))
					return true;
				return false;
			};
		while (j > i)
		{
			while (check(s[i]) == false)
				++i;
			while (check(s[j]) == false)
				--j;
			if (i > j)
				break;
			if (tolower(s[i]) != tolower(s[j]))
				return false;
			++i;
			--j;
		}
		return true;
	}
};

int main()
{
	Solution sol;
	string s1 = "A man, a plan, a canal: Panama";
	string s2 = "race a car";
	cout << sol.isPalindrome(s1) << endl;
	cout << sol.isPalindrome(s2) << endl;
	cout << sol.isPalindrome("") << endl;
}
